home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 48 / Amiga Format CD48 (1999-12-13)(Future Publishing)(GB)(Track 1 of 2)[!][issue 2000-01].iso / -serious- / programming / c / supralib / developer / source / move / main.c
C/C++ Source or Header  |  1999-11-01  |  2KB  |  68 lines

  1. /*******************************************************************
  2. *
  3. *    ---------------
  4. *   * Supra library *
  5. *    ---------------
  6. *
  7. *   -- Move file demo --
  8. *   Demonstration of FCopy() function.
  9. *
  10. *   This is a simple program that moves a source file to a
  11. *   destination file.
  12. *   Usage is: Move sfile dfile
  13. *   sfile = source file to be moved
  14. *   dfile = destination file
  15. *
  16. *   Example: move c:list ram:ls
  17. *   (will copy c:list to ram:ls, and delete c:list)
  18. *
  19. *
  20. *   ©1995 by Jure Vrhovnik -- all rights reserved
  21. *   jurev@gea.fer.uni-lj.si
  22. *
  23. *******************************************************************/
  24.  
  25. #include <clib/dos_protos.h>
  26. #include <dos/dos.h>
  27. #include <libraries/supra.h>
  28. #include <stdio.h>
  29.  
  30. int    main(int argc, char *argv[])
  31. {
  32.     UBYTE err;
  33.  
  34.     if (argc == 0)     /* Started from WB */
  35.     {
  36.         printf("Please start this from CLI\n");
  37.     }
  38.     else if (argc != 3)   /* Move needs exactly two arguments */
  39.     {
  40.         printf("Usage: %s source dest\n",argv[0]);
  41.     }
  42.     else
  43.     {
  44.         err = FCopy(argv[1], argv[2], 0);
  45.         if (err)  /* Error occured */
  46.         {
  47.             switch(err)
  48.             {
  49.                 case FC_ERR_EXIST:
  50.                     printf("%s does not exist\n", argv[1]);
  51.                     break;
  52.                 case FC_ERR_DEST:
  53.                     printf("Error writing to %s\n", argv[2]);
  54.                     break;
  55.                 default:
  56.                     printf("Error: cannot move the file\n");
  57.             }
  58.         }
  59.         else
  60.         {
  61.             if (!(DeleteFile(argv[1]))) printf("Cannot delete source file\n");
  62.             printf("File moved\n");
  63.         }
  64.     }
  65.     return(0);
  66. }
  67.  
  68.